package br.com.ordersys.framework.db.metadata;

import java.util.ArrayList;
import java.util.Collection;

public class RelationMetadata {
	private String id;
	private String name;
	private String source;
	private String target;
	private String filter;
	private String description;
	private int cardinality;
	private TableMetadata tableMetadata;

	private Collection<Link> fieldLinks;

	public static interface CARDINALITY {
		int ONE_TO_ONE = 0;
		int ONE_TO_MANY = 1;
	}

	public RelationMetadata(String id, String name, String source, String target, int cardinality) {
		this.id = id;
		this.name = name;
		this.source = source;
		this.target = target;
		this.cardinality = cardinality;
		this.fieldLinks = new ArrayList<RelationMetadata.Link>();
	}

	public void addFieldLink(String source, String target) {
		Link l = new Link();
		l.fkField = source;
		l.pkField = target;

		fieldLinks.add(l);
	}

	public Collection<Link> getFieldLinks() {
		return fieldLinks;
	}

	public String getFilter() {
		return filter;
	}

	public void setFilter(String filter) {
		this.filter = filter;
	}

	public String getName() {
		return name;
	}

	public String getSource() {
		return source;
	}

	public String getTarget() {
		return target;
	}

	public int getCardinality() {
		return cardinality;
	}

	public String getId() {
		return id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public static class Link {
		private String fkField;
		private String pkField;

		public String getFKField() {
			return fkField;
		}

		public String getPKField() {
			return pkField;
		}
	}

	public TableMetadata getTableMetadata() {
		return tableMetadata;
	}

	public void setTableMetadata(TableMetadata tableMetadata) {
		this.tableMetadata = tableMetadata;
	}

}
